<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<%@ include file="/pub/includ.jsp"%>
<html>
	<head>
		<script type="text/javascript">
		
			//对第一个frm的回调函数, 方法的命名规则为callback_+表单id	
			var callback_frm = function(rows, frm) {
		       $.each(rows, function(i, n){
		    	   var row = $("#"+frm+" .template").clone().removeClass("template");
			       row.find(".klId").attr("value",n.name);
		           row.find(".klId").attr("id",n.id);
			       row.find(".klname").text(n.name);
			       row.find(".kldescription").text(n.description);
			       row.find(".klorder_num").text(n.order_num);
		    	   
		 		   row.attr("id","ready"+i);
		           row.attr("class","tr_nbw");
		           row.appendTo("#"+frm+" .grid");
		       });
			}


			function _submit(){
				var str = top.document.getElementById("checkedIds").value;
		    	window.returnValue = str;
				window.close();
		    }
		    
		    function _checkPosition(obj){
			    var id = obj.id;
			    var positionName = obj.value;
		    	var thisPosition = document.getElementById(id);
		    	//userid1|positionName1
		    	var checkedIds = top.document.getElementById("checkedIds").value;
		    	if(thisPosition.checked){
			    	checkedIds = id+"|"+positionName;
			    }
		    	top.document.getElementById("checkedIds").value = checkedIds;
		    }
		    
		    function _ondblclick(obj){
			    var id = obj.id;
			    var positionName = obj.value;
		    	window.returnValue = id+"|"+positionName;
				window.close();
		    }
		</script>
	</head>
<body >
	<input type="hidden" id="checkedIds" name="checkedIds"/>
	<form name="frm" method="post" style="margin: 0" action="<%=path%>/sys/position/list" id="frm">
		<table><tr><td height="2px"></td></tr></table>
		&nbsp;&nbsp;&nbsp;&nbsp;
				<a href="#" onclick="_submit()">确定</a>
		<center>
		<table><tr><td height="2px"></td></tr></table>
		<table border="0" cellspacing="1" cellpadding="0" class="table_nbw  niceTable grid">
			<thead class="th_nbw">
				<tr >
					<td width="40px" >
						选择
					</td>
					<td>
						名称
					</td>
		      		<td>
						描述
					</td>   
		      		<td>
						排序
					</td>     
				</tr>
			</thead>
			<tbody>
				<tr class="template klId">
					<td width="40px" class="idCheck">
						<input type="radio" onclick="_checkPosition(this)" ondblclick="_ondblclick(this)" name="checkPosition" class="klId" />
					</td>
					<td class="klname niceTable-left"></td>
					<td class="kldescription niceTable-left"></td>
	   		    	<td class="klorder_num niceTable-left"></td>
				</tr>
			</tbody>
			<tfoot>
				<tr>
					<td align="right" colspan="10" >
						<img class="loading"
							src="<%=imgPath %>/large-loading.gif" width="20px"
							class="hidden" />
						<span class="pagediv"></span>
					</td>
				</tr>
			</tfoot>
		</table>
		</center>
	</form>
<script type="text/javascript">

$(function(){
	//加载两个要使用json分页的组件
    loadGird("frm", 1);
    setTimeout(initr,"1000");//
})

function initr(){
	var allUsers = document.getElementsByName("checkPosition");
   	var checkedIds = top.document.getElementById("checkedIds").value;
   	if(checkedIds == "|"){
   		checkedIds = document.getElementById("checkedIds").value;
   	}
   	if(allUsers){
	   	for(var i = 0;i<allUsers.length;i++){
	   		if(checkedIds.indexOf(allUsers[i].id) != -1 ){
	   			allUsers[i].checked = true;
	   			break;
	   		}
	   	}
   	}
}
</script>
</body>
</html>